﻿#ifndef APPMONITORTASKMANAGER_H
#define APPMONITORTASKMANAGER_H

#include "common.h"
#include "Logger.h"
#include <QMutex>

#include "appmonitortask.h"
#include <QObject>
#include "apprunninginfo.h"
#include "appupdatereq.h"

class AppMonitorTaskManager :public QObject
{
    Q_OBJECT

public:
    AppMonitorTaskManager();

    int loadTasksFromDB();

    void startNoStopFlagTasks();

    void oneAppMointorDeleted(AppMonitor & monitor);

    void oneAppMointorUpdated(AppMonitor & monitor);

    AppMonitorTask * getTaskByIndex(int index);

    AppMonitorTask * getTaskByAppMonitor(const AppMonitor & mointor);

    list<AppRunningInfo> getCurrentRunningInfos();

    void startTask(AppMonitorTask * task);

    void stopAndWaitTask(AppMonitorTask * task, bool stopAppByForce = false);

    int handleAppUpdateReq(AppUpdateReq * req, QString &faileReason);

    SString getApps();

    list<AppMonitorTask *> tasks;


signals:
    void taskChanged();
    void appRestarted(); //应用被监控程序重启
public:
    QMutex lock;
};

extern AppMonitorTaskManager gAppMonitorTaskManager;
#endif // APPMONITORTASKMANAGER_H
